package com.koron.css2.meterService.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.meterService.bean.query.MsReuseQueryBean;
import com.koron.css2.meterService.dto.MsReuseDto;
import com.koron.css2.meterService.mapper.MsReuseMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 复表查询
 * @author 周利斌
 *
 */
public class MsReuseList implements ServerInterface{
	
	private static Logger log = LogManager.getLogger(MsReuseList.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
		try {
			MsReuseQueryBean bean = JsonUtils.objectToPojo(req.getData(), MsReuseQueryBean.class);
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			MsReuseMapper mapper = factory.getMapper(MsReuseMapper.class);
			List<MsReuseDto> data = mapper.selectMsReuseList(bean);
			data.parallelStream().forEach(t -> {
				t.setProcessStateName(Tools.transProcessStatus(t.getProcessState()));
			});
			info.setData(new PageInfo<MsReuseDto>(data));
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("查询失败");
			log.error(e.getMessage(), e);
		}
		return info;
	}

}
